import { deepStrictEqual, strictEqual } from 'assert';
import { Mock } from 'lite-ts-mock';
import { TreePSD } from 'psd';

import { SpriteConverter as Self } from './sprite';

describe('src/scene/service/converter/sprite.ts', () => {
    describe('.convert()', () => {
        it('ok', async () => {
            const mockTreePSD = new Mock<TreePSD>();
            const self = new Self(null as any, null as any, null as any, mockTreePSD.actual);

            mockTreePSD.expectReturn(
                r => r.get('name'),
                'a'
            );

            Reflect.set(self, 'createNode', (arg: any) => {
                deepStrictEqual(arg, {
                    name: 'sprite-a'
                });
                return 'node';
            });

            Reflect.set(self, 'appendSprite', (arg: any, arg1: any) => {
                strictEqual(arg, mockTreePSD.actual);
                strictEqual(arg1, 'node');
            });

            const res = await self.convert();
            strictEqual(res, 'node');
        });

        it('.Sprite', async () => {
            const mockTreePSD = new Mock<TreePSD>();
            const self = new Self(null as any, null as any, null as any, mockTreePSD.actual);

            mockTreePSD.expectReturn(
                r => r.get('name'),
                'a.Sprite'
            );

            Reflect.set(self, 'createNode', (arg: any) => {
                deepStrictEqual(arg, {
                    name: 'sprite-a',
                });
                return 'node';
            });

            Reflect.set(self, 'appendSprite', (arg: any, arg1: any) => {
                strictEqual(arg, mockTreePSD.actual);
                strictEqual(arg1, 'node');
            });

            const res = await self.convert();
            strictEqual(res, 'node');
        });
    });
})